const axios = require('axios');
const MockAdapter = require('axios-mock-adapter');
const normalAxios = axios.create();
const mockAxios = axios.create();
import { jsonToTree } from "../utils/tools";
import Config from "./config";
import reqTools from "../utils/reqTools";

// mock 数据
var mock = new MockAdapter(mockAxios);

mock.onPost('/getApay').reply((config) => {
    config.data=JSON.parse(config.data);
    var params="body="+config.data.body+"&type="+config.data.type+"&total_fee="+config.data.total_fee;
    return new Promise(function(resolve, reject) { 
      reqTools.post('/api/onlinePay/alipay/getPaytTwoDimensionUrl?'+params).then((res) => {
       resolve([200, res ]);
     }).catch((err) => {
       resolve([500, err ]);
     });
   });
});

mock.onPost('/getXpay').reply((config) => {
    config.data=JSON.parse(config.data);
    var params="body="+config.data.body+"&type="+config.data.type+"&total_fee="+config.data.total_fee;
    return new Promise(function(resolve, reject) { 
        reqTools.post('/api/onlinePay/wxpay/getPaytTwoDimensionUrl?'+params).then((res) => {
            resolve([200, res ]);
        }).catch((err) => {
           resolve([500, err ]);
        });
    });
});


mock.onPost('/checkPay').reply((config) => {
    config.data=JSON.parse(config.data);
    return new Promise(function(resolve, reject) { 
        reqTools.post('/api/onlinePay/checkPayState?id='+config.data.id).then((res) => {
            resolve([200, res ]);
        }).catch((err) => {
           resolve([500, err ]);
        });
    });
});

export default mockAxios;
